from http.server import HTTPServer, BaseHTTPRequestHandler

host = ('', 8000)


class TodoHandle(BaseHTTPRequestHandler):
    def do_GET(self):
        from urllib.parse import urlparse, parse_qsl
        import json

        parsed_url = urlparse(self.path)
        qs = dict(parse_qsl(parsed_url.query))
        a = int(qs.get('a', 0))
        b = int(qs.get('b', 0))

        self.send_response(200)
        self.send_header('Content-type', "application/json")
        self.end_headers()

        self.wfile.write(json.dumps({
            "result": a + b
        }).encode("utf-8"))


if __name__ == '__main__':
    server = HTTPServer(host, TodoHandle)
    print("listen at: %s:%s" % host)
    server.serve_forever()
